home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: Converting Strings to Upper Case
- Date: Tue, 19 Mar 1996 13:43:03 GMT
- Organization: Netcom
- Message-ID: <314eb83f.308884702@nntp.ix.netcom.com>
- References: <4ifra6$52i@scipio.cyberstore.ca> <4ih7l3$526@thrush.sover.net> <4ihl4m$4ca@castle.nando.net> <NEWTNews.827184423.14391.breese@PC_Breese.physio-control>
- NNTP-Posting-Host: ix-dc8-01.ix.netcom.com
- X-NETCOM-Date: Tue Mar 19 7:42:01 AM CST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- Brian Reese <breese@kahuna> wrote:
-
- >
- > Here's my offering:
- >
- > #include <stdio.h> /* for printf() */
- > #include <ctype.h> /* for toupper() */
- >
- > char * strtoupper( char * ); /* converts string to upper case */
- >
- > int main( void )
- > {
- > char * test = "my test string";
- >
- > printf( "%s\n", test );
- > printf( "%s\n", strtoupper( test ) );
- >
- > return 0;
- > }
- >
- > char * strtoupper( char * ptr ) /* converts string to upper case */
- > {
- > char * save_ptr = ptr; /* save pointer for return */
- >
- > while ( *ptr = toupper( *ptr++ ) )
- > ;
- > return save_ptr;
- > }
-
- Not a very good offering. There are two obvious problems in your
- example.
-
- First, the identifier strtoupper with external linkage is reserved.
- Defining your own function with external linkage with this name
- results in undefined behavior.
-
- Second, the expression
-
- *ptr = toupper( *ptr++ )
-
- modifies ptr and also acesses its value other than to determine the
- new value without an intervening sequence point. This too results in
- undefined behavior.
-
- Michael M Rubenstein
-